package com.candy.service;

import java.util.LinkedHashMap;
import java.util.LinkedList;

import com.candy.dao.DBHelper;

public class UserInfoService {
	
	public LinkedList<LinkedHashMap<String, Object>> getUserInfoes(String username) {
		String sqlString="";
		if(username!=""&&username!=null) {
			sqlString="select * from userinfo where username like ?";
			return DBHelper.query(sqlString,"%"+username+"%");
		}else {
			sqlString="select * from userinfo";
			return DBHelper.query(sqlString);
		}						
	}

	public boolean addUserInfo(String username,String userpwd,String useraddress,String usertel) {
		String sql="insert into userinfo(username,userpwd,useraddress,usertel) values(?,?,?,?)";
		int num=DBHelper.update(sql, username,userpwd,useraddress,usertel);
		if(num>0) {
			return true;
		}else {
			return false;
		}
	}
	public LinkedList<LinkedHashMap<String, Object>> getUserInfoById(int userid) {
		String sql="select * from userinfo where id=?";
		return DBHelper.query(sql, userid);
		
	}
	public boolean updateUserInfo(String username,String userpwd,String useraddress,String usertel,int userid) {
		String sql="UPDATE userinfo SET username=?,userpwd=?,useraddress=?,usertel=? WHERE id=?";
		int num=DBHelper.update(sql, username,userpwd,useraddress,usertel,userid);
		if(num>0) {
			return true;
		}else {
			return false;
		}
	}
	public boolean deleteUserInfo(int userid) {
		String sql="delete from userinfo where id=?";
		int num=DBHelper.update(sql, userid);
		if(num>0) {
			return true;
		}else {
			return false;
		}
	}
}
